{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Gemini"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好！很高兴为你服务。有什么我可以帮到你的吗？\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from google import genai\n",
    "\n",
    "client = genai.Client(api_key=\"AIzaSyB2Atc4agblDdsqa3_xKh3_K81tr2OW0t8\")\n",
    "\n",
    "response = client.models.generate_content(\n",
    "    model=\"gemini-2.0-flash\",\n",
    "    contents='你好',\n",
    ")\n",
    "\n",
    "print(response.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# deepseek(非必要少用，要给钱，尝试代码先用gemini)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "翻译：\n",
      "问题：世界上有多少家7-11便利店？\n",
      "答案：截至2024年7月，全球有超过77,000家7-11便利店。\n",
      "\n",
      "判断：是幻觉现象。根据公开资料，截至2023年，全球7-11便利店的数量约为7万家左右，而不是77,000家。这个回答明显夸大了实际数量。\n"
     ]
    }
   ],
   "source": [
    "# Please install OpenAI SDK first: `pip3 install openai`\n",
    "\n",
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(api_key=\"sk-345d4d96bd464da2bfebb09bc43b4aa4\", base_url=\"https://api.deepseek.com\")\n",
    "\n",
    "response = client.chat.completions.create(\n",
    "    model=\"deepseek-chat\",\n",
    "    messages=[\n",
    "        {\"role\": \"system\", \"content\": \"你是 deepseek，我下面会给你一个问题以及一个别的大语言模型给出的答案，请你判断这个回答是否出现幻觉现象，你先翻译一下问题和答案，然后需要回答是或不是\"},\n",
    "        {\"role\": \"user\", \"content\": \"问题为：how many 7 elevens are in the world；答案为：As of July 2024, there are over 77,000 7 - Eleven stores worldwide. \"}\n",
    "    ],\n",
    "    stream=False\n",
    ")\n",
    "\n",
    "print(response.choices[0].message.content)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 豆包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "As of July 2024, there are over 77,000 7 - Eleven stores worldwide. \n"
     ]
    }
   ],
   "source": [
    "!export ARK_API_KEY=\"01e37152-1149-4888-8c3c-0fb25cf40c4b\"\n",
    "import os\n",
    "from openai import OpenAI\n",
    "\n",
    "ark_API_KEY =\"01e37152-1149-4888-8c3c-0fb25cf40c4b\"\n",
    "\n",
    "# Set the OpenAI API key via environment variable\n",
    "os.environ[\"ARK_API_KEY\"] = \"01e37152-1149-4888-8c3c-0fb25cf40c4b\"\n",
    "\n",
    "\n",
    "# 请确保您已将 API Key 存储在环境变量 ARK_API_KEY 中\n",
    "# 初始化Ark客户端，从环境变量中读取您的API Key\n",
    "client = OpenAI(\n",
    "    # 此为默认路径，您可根据业务所在地域进行配置\n",
    "    base_url=\"https://ark.cn-beijing.volces.com/api/v3\",\n",
    "    # 从环境变量中获取您的 API Key。此为默认方式，您可根据需要进行修改\n",
    "    api_key=\"01e37152-1149-4888-8c3c-0fb25cf40c4b\"\n",
    ")\n",
    "\n",
    "response = client.chat.completions.create(\n",
    "    # 指定您创建的方舟推理接入点 ID，此处已帮您修改为您的推理接入点 ID\n",
    "    model=\"doubao-1-5-vision-pro-32k-250115\",\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": [\n",
    "                {\"type\": \"text\", \"text\": \"how many 7 elevens are in the world,回答可以简短一点\"},\n",
    "            ],\n",
    "        }\n",
    "    ],\n",
    ")\n",
    "\n",
    "# print(response.choices[0])\n",
    "\n",
    "print(response.choices[0].message.content)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# kimi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "问题翻译：在狗身上他们把芯片放在哪里？\n",
      "答案翻译：在消化道里。这个由厚肌肉壁构成的特殊胃被用来磨碎食物，通常还需要石头或沙粒的颗粒来辅助。\n",
      "\n",
      "判断：出现了幻觉现象。实际上，狗身上的芯片通常是被植入在皮肤下，通常是在颈部的位置，而不是消化道或胃中。芯片用于宠物识别和追踪，而不是帮助消化。\n"
     ]
    }
   ],
   "source": [
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key = \"sk-axOmPx6vqeZSYVSg4urvyjsw0VzogFN70tQCqGuO4hAPKKOR\",\n",
    "    base_url = \"https://api.moonshot.cn/v1\",\n",
    ")\n",
    "\n",
    "completion = client.chat.completions.create(\n",
    "    model = \"moonshot-v1-8k\",\n",
    "    messages = [\n",
    "        {\"role\": \"system\", \"content\": \"你是 Kimi，我下面会给你一个问题以及一个别的大语言模型给出的答案，请你判断这个回答是否出现幻觉现象，你先翻译一下问题和答案，然后需要回答是否出现了幻觉现象。\"},\n",
    "        {\"role\": \"user\", \"content\": \"问题为：where do they put the chip in dogs；答案为：in the digestive tract. This specialized stomach constructed of thick muscular walls is used for grinding up food , often aided by particles of stone or grit .\"}\n",
    "    ],\n",
    "    temperature = 0.3,\n",
    ")\n",
    "\n",
    "print(completion.choices[0].message.content)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# qwen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我是通义千问，阿里巴巴集团旗下的通义实验室自主研发的超大规模语言模型。我能够回答问题、创作文字，如写故事、公文、邮件、剧本等，还能进行逻辑推理、编程，甚至表达观点和玩游戏。我在多国语言上都有很好的掌握，能为你提供多样化的帮助。如果你有任何问题或需要创作内容，都可以告诉我，我会尽力协助你。\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    # 若没有配置环境变量，请用百炼API Key将下行替换为：api_key=\"sk-xxx\",\n",
    "    api_key=\"sk-fb3964c128a74650be4c226d9b7dd9bc\",\n",
    "    base_url=\"https://dashscope.aliyuncs.com/compatible-mode/v1\",\n",
    ")\n",
    "completion = client.chat.completions.create(\n",
    "    model=\"qwen-plus\", # 此处以qwen-plus为例，可按需更换模型名称。模型列表：https://help.aliyun.com/zh/model-studio/getting-started/models\n",
    "    messages=[\n",
    "        {'role': 'system', 'content': 'You are a helpful assistant.'},\n",
    "        {'role': 'user', 'content': '你是谁？'}],\n",
    "    )\n",
    "\n",
    "print(completion.choices[0].message.content)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
